package com.simon.mengkou.future.handler;

import android.content.Context;

import com.ouertech.android.agm.lib.base.future.http.HttpEvent;
import com.simon.mengkou.data.bean.base.Address;
import com.simon.mengkou.data.bean.base.Image;
import com.simon.mengkou.data.bean.base.WishProduct;
import com.simon.mengkou.data.bean.req.IdReq;
import com.simon.mengkou.data.bean.req.PageReq;
import com.simon.mengkou.data.cache.DataCacheImpl;
import com.simon.mengkou.future.base.OuerFutureData;
import com.simon.mengkou.future.base.OuerHttpHandler;
import com.simon.mengkou.system.global.OuerApplication;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xiazhenshui on 16/7/21.
 * 心愿单业务逻辑
 */

public class WishListHandler extends OuerHttpHandler {
    PageReq mReq;

    public WishListHandler(Context context) {
        super(context);
    }

    @Override
    public boolean onEncode(HttpEvent evt) throws Exception {
        OuerFutureData futureData = (OuerFutureData)evt.getData();
        mReq = (PageReq) futureData.getReq();
        return super.onEncode(evt);
    }

    @Override
    public void onHandle(HttpEvent evt) throws Exception {
        List<WishProduct> datas = (List<WishProduct>) evt.getData();
        if(mReq.getPage() == 0) {
            OuerApplication.mCacheFactory.getCache(DataCacheImpl.WishListCache.class,
                    OuerApplication.mUser.getUserId()).save(datas);
        }

        evt.getFuture().commitComplete(datas);
    }
}
